home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96b.txt
/
000052_icon-group-sender _Wed Nov 6 14:25:10 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1997-01-02
|
3KB
Received: by cheltenham.cs.arizona.edu; Wed, 6 Nov 1996 16:41:53 MST
To: icon-group@cs.arizona.edu
Date: Wed, 06 Nov 1996 14:25:10 -0700
From: Steve Wampler <swampler@gemini.edu>
Message-Id: <32810236.3855@gemini.edu>
Organization: Gemini 8m Telescopes Project
Sender: icon-group-request@cs.arizona.edu
References: <55qhto$66r@netty.york.ac.uk>
Subject: Re: sets and structures
Errors-To: icon-group-errors@cs.arizona.edu
stephen parker wrote:
>
> i'm reading ``An Overview of the Icon Programming Language; Version 8''
> (Griswold). the section on sets says: ``insert(S, x) has no effect if x
> is already in S''.
>
> this appears to work for atomic types eg,
...
>
> however, if if i try to insert a structure then it never fails,
...
> as you would expect for a list rather than a set. so, what's the answer
> if you want to form a set of non-atomic types? do i have to do it by
> hand?
Actually, both you and book are both correct. The definition of a
structured value is such that each such value is unique, even if
they look the same.
There is no easy fix that works for arbitrary structured arguments.
{A good exam question is "Why?"...}
For simple cases, such as the example you give, you could call
a procedure that would produce a string that "looks like" the
record with string-valued fields [note that image(rec(a,b)) does
not work here], and then insert this string into the table. Nor
will any of the similar routines provided in the Icon Programming
Language, since they all (image() and the others) tag each string
representation for a structure with a unique id, just what you
want to avoid... {hmmm, good homework assignment...}
Personally, I would then use a table instead of a set. Put the
record itself as the value of an entry whose key is the "lookalike"
string. That way you can pull the record out from the 'set'...
Assuming that sImage(x) does this 'conversion' to string, and, using
a table instead of a set, your code could be written as:
procedure main()
local l, s, r, a, b
s := table()
while(l := read()) do {
a := l[1]
b := l[2:0]
r := rec(a,b)
s[sImage(r)] := r
}
every l := !s do
write(l.a, " ", l.b)
end
For this simple case, here is a suitable sImage():
procedure sImage(x)
return x.a||" "||x.b
end
It's generalizing this that is hard...
--
Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under
AURA)]
The Gods that smiled upon your birth are laughing now. -- fortune cookie